<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>

<body>
    <script>
        // 工厂函数 ==> 实现批量创建对象
        //构造函数
        function Person(name, age) {
            this.name = name;
            this.age = age;
        }
        var p1 = new Person('小红', 18);
        console.log(p1);
        var p2 = new Person('小黄', 2);
        console.log(p2); //复杂 每次new
        //工厂函数内部 new 构造函数
        function $(name, age) {
            return new Person(name, age); //自己不用new 封装函数去new
        }
        var p3 = $('xiaohone', 20);
        console.log(p3);
    </script>
</body>

</html>